package com.demo2do.fms.admin.entity.search.data;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;

/**
 *
 * @author Ark
 *
 */
public class VehicleSearch implements QueryBuilder {
    
    /** 所属公司 */
    private List<Long> organizationIds;
    
    /** 驳运车代码 */
    private String code;
    
    /** 驳运车牌照 */
    private String barCode;
    
    /** 动力类型 */
    private Long  vehicleFeatureId;
    
    /** 车队id */
    private Long teamId;
    
    /** 累计行驶公里数 - start */
    private BigDecimal beginDistance;
    
    /** 累计行驶公里数 - end */
    private BigDecimal endDistance;
    
    private QueryFilter filter;
    
    private QueryOrder order;
    
    /**
     * The default constructor
     */
    public VehicleSearch() {
        order = new QueryOrder();
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {
        
        if (filter == null || refresh) {
            
            filter = new QueryFilter().addSentence("organization.id IN (:organizationIds)", "organizationIds", organizationIds)
                                      .addLike("code", code)
                                      .addLike("barCode", barCode)
                                      .addEquals("vehicleFeature.id", vehicleFeatureId)
                                      .addEquals("teamId", teamId)
                                      .addGreaterThan("beginDistance", beginDistance)
                                      .addLessThan("endDistance", endDistance);
            
        }
        
        return filter;
        
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return order;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = "FROM Vehicle Where disabled = false" + getPreparedFilter(false).clauseSentence() + order.sentence();
        return sentence;
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * @return
     */
    public QueryFilter getFilter() {
        return getPreparedFilter(false);
    }
    
    /**
     * @return the organizationIds
     */
    public List<Long> getOrganizationIds() {
        return organizationIds;
    }

    /**
     * @return the code
     */
    public String getCode() {
        return code;
    }

    /**
     * @return the barCode
     */
    public String getBarCode() {
        return barCode;
    }

    /**
     * @return
     */
    public Long getVehicleFeatureId() {
        return vehicleFeatureId;
    }

    /**
     * @return the teamId
     */
    public Long getTeamId() {
        return teamId;
    }

    /**
     * @return the beginDistance
     */
    public BigDecimal getBeginDistance() {
        return beginDistance;
    }

    /**
     * @return the endDistance
     */
    public BigDecimal getEndDistance() {
        return endDistance;
    }

    /**
     * @param organizationIds the organizationIds to set
     */
    public void setOrganizationIds(List<Long> organizationIds) {
        this.organizationIds = organizationIds;
    }

    /**
     * @param code the code to set
     */
    public void setCode(String code) {
        this.code = code;
    }

    /**
     * @param barCode the barCode to set
     */
    public void setBarCode(String barCode) {
        this.barCode = barCode;
    }

    /**
     * @param vehicleFeatureId
     */
    public void setVehicleFeatureId(Long vehicleFeatureId) {
        this.vehicleFeatureId = vehicleFeatureId;
    }

    /**
     * @param teamId the teamId to set
     */
    public void setTeamId(Long teamId) {
        this.teamId = teamId;
    }

    /**
     * @param beginDistance the beginDistance to set
     */
    public void setBeginDistance(BigDecimal beginDistance) {
        this.beginDistance = beginDistance;
    }

    /**
     * @param endDistance the endDistance to set
     */
    public void setEndDistance(BigDecimal endDistance) {
        this.endDistance = endDistance;
    }
    
}
